package com.supertool.monitor;
import java.lang.Math;
import java.util.Random;

/**
 * Created by supertool on 2014/11/5.
 */
    public class LogKey implements Comparable<LogKey> {
        private boolean isMinisite;
        private String minid;
        private String uuid;
        private String caid;
        private int time;
        private String line;
        private String ip;
        public LogKey(String uuid, String caid,String minid, int time,boolean isMinisite,String ip){
            this.uuid = uuid;
            this.caid = caid;
            this.minid=minid;
            this.time = time;
            this.isMinisite=isMinisite;
            this.ip=ip;
        }

        public boolean isMinisite(){
            return this.isMinisite;
        }

        public String getMinid(){
            return minid;
        }

        public String getUuid() {
            return uuid;
        }
        public void setUuid(String uuid) {
            this.uuid = uuid;
        }
        public String getCaid() {
            return caid;
        }

        public String getMeta(){
            if (isMinisite){
                return "ms_"+this.minid;
            }
            return "ca_"+this.caid;
        }

        public void setCaid(String caid) {
            this.caid = caid;
        }
        public int getTime() {
            return time;
        }
        public void setTime(int time) {
            this.time = time;
        }
        public String getIp(){
            return ip;
        }
        public void setIp(String ip){
            this.ip = ip;
        }
        public boolean lessthan(LogKey key) {
        /*
        if ((int)(Math.random()*50) > 25) {
            return false;
        } else {
            return true;
        }
        */

            if(this.isMinisite!=key.isMinisite){
                //Minisite<Campaign
                return isMinisite;
            }
            int res;
            if(isMinisite){
                res=minid.compareTo(key.minid);
            }else{
                res=caid.compareTo(key.caid);
            }
            //return false;
            //*
            if(res!=0)
                return res<0;
            res=uuid.compareTo(key.uuid);
            if(res!=0)
                return res<0;
            res=time-key.getTime();
            if(res!=0)
                return res<0;
            return ip.compareTo(key.ip)<0;
            //*/
        }
        @Override
        public String toString() {
            return this.getMeta();
        }
        public int compareTo(LogKey o) {
            if (this.lessthan(o)){
                return -1;
            }
            if(o.lessthan(this)){
                return 1;
            }
            return 0;
        }
    }

